<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Fee_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 记录用户推广提成信息
	 */
	public function create($fee){
		$this->db->insert('t_fee', $fee);
		return $this->db->insert_id();
	}
	/*
	 * 根据搜索名称返回符合记录的数量
	 */
	public function count_fees($id,$name){
		$this->db->join('t_user', 't_user.id = t_fee.userid','left');
		if(!empty($name)){
			$this->db->like('shopname', $name);
		}
		$this->db->where('t_fee.promoterid', $id);
		$query = $this->db->get('t_fee');
		return $query->num_rows();
	}
	/*
	 * 根据搜索名称和分页信息返回符合的记录列表
	 */
	public function find_all_fees($id,$name,$per_page,$offset){//
		$this->db->select('t_fee.id,t_user.shopname,t_fee.amount,t_fee.date');
		$this->db->from('t_fee');
		$this->db->join('t_user', 't_user.id = t_fee.userid','left');
		if(!empty($name)){
			$this->db->like('shopname', $name);
		}
		$this->db->where('t_fee.promoterid', $id);
		$this->db->limit($per_page, $offset);
		$this->db->order_by("id", "desc");
		$query=$this->db->get();
		return $query->result_array();
	}
}